//
//  MyLayout.m
//  自定义布局 练习
//
//  Created by dllo on 16/8/19.
//  Copyright © 2016年 yh. All rights reserved.
//

#import "MyLayout.h"

@interface MyLayout ()
@property (nonatomic, strong) NSMutableArray<UICollectionViewLayoutAttributes *> *attributesArray;

@property (nonatomic, assign) CGFloat itemWidth;
@property (nonatomic, assign) CGFloat contentHeight;
@property (nonatomic, assign) NSInteger numOfColumn;
@property (nonatomic, assign) CGFloat cellMargin;

@end


@implementation MyLayout
- (instancetype)init {
    self = [super init];
    if (self) {
        self.attributesArray = [NSMutableArray array];
        self.numOfColumn = 2;
        self.contentHeight = 0;
        self.cellMargin = 5;
    }
    return self;
}

- (CGFloat)itemWidth {
    CGFloat allCellMargin = (self.numOfColumn + 1) * self.cellMargin;
    return (self.collectionView.bounds.size.width - allCellMargin) / self.numOfColumn;
}

- (void)prepareLayout {
    NSInteger column = 0;
    for (NSInteger i = 0; i < [self.collectionView numberOfItemsInSection:0]; i++) {
        NSIndexPath *index = [NSIndexPath indexPathForItem:i inSection:0];
    
        UICollectionViewLayoutAttributes *attributes = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:index];
        CGFloat x = self.itemWidth * column + self.cellMargin * column;
        CGFloat y = self.cellMargin
}


}












@end
